# -*- coding: utf-8 -*-
from docx import Document
from docx.shared import RGBColor
from docx.oxml.ns import qn

doc = Document()
p = doc.add_paragraph()
from docx.oxml.ns import qn

doc.styles['Normal'].font.name = u'微软雅黑'
doc.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
text_str = u'一个人的命运啊，当然要靠自我奋斗，但是也要考虑到历史的进程。'
# for i, ch in enumerate(text_str):
#     run = p.add_run(ch)
#     font = run.font
#     font.name = u'微软雅黑'
#     # bug of python-docx
#     run._element.rPr.rFonts.set(qn('w:eastAsia'), u'微软雅黑')
#     font.bold = (i % 2 == 0)
#     font.italic = (i % 3 == 0)
#     color = font.color
#     color.rgb = RGBColor(i * 10 % 200 + 55, i * 20 % 200 + 55, i * 30 % 200 + 55)
p = doc.add_paragraph('hello world linfeng'+text_str)
run = p.add_run('文本颜色测试')
run.font.color.rgb= RGBColor(22, 120, 190)
p.add_run('颜色文本')
print(dir(run.font.color))

doc.save('4-3.docx')
